<template>
    <div class="table">
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" @click="addCount">新增</el-button>
                <el-button type="success" @click="editRole">修改</el-button>
                <el-button type="danger" @click="delCount">删除</el-button>
                <el-button type="primary" icon="el-icon-video-play" @click="connect(0)">链接</el-button>
                <el-button type="danger" icon="el-icon-video-pause" @click="connect(1)">断开</el-button>
<!--                <el-button type="primary" @click="configMid">配置中继</el-button>-->
            </div>
            <el-table :data="tableData" border stripe class="table" ref="multipleTable" @selection-change="handleSelectionChangeTable" @row-click="handleRowClick">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="deviceName" align="center" label="名称">
                </el-table-column>
                <el-table-column prop="deviceCode" align="center" label="编号">
                </el-table-column>
                <el-table-column prop="deviceNo" align="center" label="产品序号">      
                </el-table-column>
                <el-table-column prop="comTypeName" align="center" label="通讯类型">
                </el-table-column>
                <el-table-column prop="ipAddress" align="center" label="通讯配置" :formatter="formatAdd">
                </el-table-column>
                <el-table-column prop="deviceStatus" align="center" label="通讯状态">
                </el-table-column>
<!--                <el-table-column prop="linkNo" align="center" label="中继编号">-->
<!--                </el-table-column>-->
                <el-table-column prop="faultDescription" align="center" label="故障说明">{{faultDescription}}
                </el-table-column>
                <el-table-column prop="comProtocalName" align="center" label="网关协议">
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background @current-change="handleCurrentChange" layout="prev, pager, next" :total="page_total" :page-size="page_size">
                </el-pagination>
            </div>
        </div>
        <!-- 新增网关弹出框 -->
        <el-dialog :title="diologTitle" :visible.sync="addVisible" width="70%" >
            <el-form :model="form"  ref="Form" label-width="144px" class="limit-small" :rules="rules">
                <el-form-item label="编号" class="limit-width active" prop="code">
                    <el-input v-model="form.code"></el-input>
                </el-form-item>
                <el-form-item label="名称" class="limit-width active" prop="name">
                    <el-input v-model="form.name"></el-input>
                </el-form-item >
                <el-form-item label="序号 :" class="limit-width active" prop="order">
                    <el-input class="el_input form_wid"  v-model="form.order"></el-input>
                </el-form-item >
                <el-form-item label="网关协议" class="limit-width active" prop="concentratorAgreement">
                    <el-select v-model="form.concentratorAgreement"   placeholder="请选择">
                        <el-option
                                v-for="item in concentratorAgreementType"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="通讯协议 :" class="limit-width" style="width: 50%;" prop="communication">
                    <el-select v-model="form.communication"  placeholder="请选择">
                        <el-option
                                v-for="item in communicationType"
                                :key="item.value"
                                :label="item.name"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                        <div v-if="form.communication==communicationType[0].value">
                            <el-form-item label="IP地址 :" class="limit-width active" prop="IPAddress">
                                            <el-input class="el_input form_wid"  v-model="form.IPAddress" prop="IPAddress"></el-input>
                            </el-form-item>
                            <el-form-item label="端口 :" class="limit-width active" prop="port">
                                                <el-input class="el_input form_wid"  v-model="form.port" prop="port"></el-input>
                            </el-form-item>
                            <el-form-item label="发送超时时间(ms) :" class="limit-width active" prop="moreTime">
                                <el-input class="el_input form_wid"  v-model="form.moreTime" prop="moreTime"></el-input>
                            </el-form-item>
                            <el-form-item label="接受超时时间(ms) :" class="limit-width active" prop="reciveTime">
                                <el-input class="el_input form_wid"  v-model="form.reciveTime" prop="reciveTime"></el-input>
                            </el-form-item>

                        </div>
                        <div v-else-if="form.communication==communicationType[1].value">
                            <el-form-item label="串口号 :" class="limit-width active" prop="seriaPort">
                                <el-select v-model="form.seriaPort"  placeholder="请选择">
                                    <el-option
                                            v-for="item in 255"
                                            :key="item"
                                            :label="'COM'+item"
                                            :value="'COM'+item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="波特率 :" class="limit-width active" prop="baudRate">
                                <el-select v-model="form.baudRate"  placeholder="请选择">
                                    <el-option
                                            v-for="item in baudRateType"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.label">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="数据位 :" class="limit-width active" prop="numPosition">
                                <el-select v-model="form.numPosition"  placeholder="请选择">
                                    <el-option
                                            v-for="item in numPositionType"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.label">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="停止位 :" class="limit-width active" prop="stopPosition">
                                <el-select v-model="form.stopPosition"  placeholder="请选择">
                                    <el-option
                                            v-for="item in stopPositionType"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="parseInt(item.value)">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                                <el-form-item label="奇偶校验位 :" class="limit-width active" prop="parityBit">
                                <el-select v-model="form.parityBit"  placeholder="请选择">
                                    <el-option
                                            v-for="item in parityBitType"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="parseInt(item.value)">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="发送超时时间(ms) :" class="limit-width active" prop="moreTime">
                                <el-input class="el_input form_wid"  v-model="form.moreTime" prop="moreTime"></el-input>
                            </el-form-item>
                            <el-form-item label="接受超时时间(ms) :" class="limit-width active" prop="reciveTime">
                                <el-input class="el_input form_wid"  v-model="form.reciveTime" prop="reciveTime"></el-input>
                            </el-form-item>
                        </div>
                        <div v-else="form.communication==communicationType[2].value">
                            <el-form-item label="IP地址 :" class="limit-width active" prop="IPAddress">
                                <el-input class="el_input form_wid"  v-model="form.IPAddress" prop="IPAddress"></el-input>
                            </el-form-item>
                            <el-form-item label="端口号 :" class="limit-width active" prop="port">
                                <el-input class="el_input form_wid"  v-model="form.port" prop="port"></el-input>
                            </el-form-item>
                            <el-form-item label="发送超时时间(ms) :" class="limit-width active" prop="moreTime">
                                <el-input class="el_input form_wid"  v-model="form.moreTime" prop="moreTime"></el-input>
                            </el-form-item>
                            <el-form-item label="接受超时时间(ms) :" class="limit-width active" prop="reciveTime">
                                <el-input class="el_input form_wid"  v-model="form.reciveTime" prop="reciveTime"></el-input>
                            </el-form-item>
                            <el-form-item label="IMEI号 :" class="limit-width active" prop="Imei">
                                <el-input class="el_input form_wid"  v-model="form.Imei" prop="Imei"></el-input>
                            </el-form-item>
                             <el-form-item label="远程端口号 :" class="limit-width active" prop="endName">
                                <el-input class="el_input form_wid"  v-model="form.endName" prop="endName"></el-input>
                        </el-form-item>
                        </div>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="save">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>

<!--        中继选择-->
<!--        <el-dialog title="选择中继链路" :visible.sync="isConfigMid" width="30%">-->
<!--            <div>-->
<!--                <template>-->
<!--                    <span>中继链路名称：</span>-->
<!--                    <el-select v-model="configMidData" placeholder="请选择">-->
<!--                        <el-option-->
<!--                                v-for="item in configMidDataList"-->
<!--                                :key="item.id"-->
<!--                                :label="item.repeaterName"-->
<!--                                :value="item.id" style="padding-left: 15px;">-->
<!--                        </el-option>-->
<!--                    </el-select>-->
<!--                </template>-->
<!--            </div>-->

<!--            <span slot="footer" class="dialog-footer">-->
<!--                <el-button @click="isConfigMid = false">取 消</el-button>-->
<!--                <el-button type="primary" @click="savaConfig">确 定</el-button>-->
<!--            </span>-->
<!--        </el-dialog>-->
    </div>
</template>

<script>
    import {getAdministrationPage,getCategory,addDataCollector,updateDataCollector,batchDeleteDataCollectors,getRepeaterLinkList,setDataCollectorRepeaterInfo} from '../../../api/index';
    import {famatDatesTimes,regNumber,regIpAddress} from '../../common/com'
    import {apiLoading} from '../../../config/index'

    export default {
        name: "GatewayAdministration",
        data() {
            return {
                deviceStates:'未连接',//通讯状态
                faultDescription:'',//故障说明
                tableData:[],
                cur_page: 1,
                page_size:10,
                page_total:1,
                multipleSelection: [],//当前行
                // multipleSelectionTable:[],
                diologTitle:'新增网关',
                addVisible:false,
                isEditInfo:false,
                delVisible:false,
                form: {
                    name: '',//名称
                    order: '',//序号
                    code:'',//编号
                    communication:'',//通讯方式
                    IPAddress:'',//IP地址
                    port:'',//端口
                    moreTime:'',//超时时间
                    reciveTime:'',//接收时间
                    seriaPort:'',// 串口号
                    baudRate:'',//波特率
                    numPosition:'',//数据位
                    stopPosition:'',//停止位
                    parityBit:'',//奇偶校验位
                    Imei:'',//Imei号
                    endName:'',//远程端口
                    concentratorAgreement:'',//网关协议
                },
                //网关协议
                concentratorAgreementType:[],
                //通讯方式
                communicationType:[{"name":"","value":""},{"name":"","value":""},{"name":"","value":""}],
                //串口号
                portType:[
                    {
                        value:'1',
                        label:'COM1'
                    },
                    {
                        value:'2',
                        label:'COM2'
                    },
                    {
                        value:'3',
                        label:'COM3'
                    },
                    {
                        value:'4',
                        label:'COM4'
                    },
                    {
                        value:'5',
                        label:'COM5'
                    }
                ],
                //波特率
                baudRateType:[
                    {
                        value:'1',
                        label:'9600'
                    },
                    {
                        value:'2',
                        label:'14400'
                    },
                    {
                        value:'3',
                        label:'19200'
                    },
                    {
                        value:'4',
                        label:'38400'
                    },
                    {
                        value:'5',
                        label:'54000'
                    },
                    {
                        value:'6',
                        label:'57600'
                    },
                    {
                        value:'7',
                        label:'115200'
                    },
                    {
                        value:'8',
                        label:'128000'
                    },
                    {
                        value:'9',
                        label:'256000'
                    },
                ],
                //数据位
                numPositionType:[
                    {
                        value:'1',
                        label:'4'
                    },
                    {
                        value:'2',
                        label:'5'
                    },
                    {
                        value:'3',
                        label:'6'
                    },
                ],
                stopPositionType:[
                    {
                        value:'0',
                        label:'One'
                    },
                    {
                        value:'1',
                        label:'Two'
                    },
                    {
                        value:'3',
                        label:'Three'
                    },
                ],
                parityBitType:[
                    {
                        value:'0',
                        label:'Even'
                    },
                    {
                        value:'1',
                        label:'Odd'
                    }
                ],
                rules:{
                    code :[{required: true, message: '请输入', trigger: 'blur'}],//编号
                    name :[{required: true, message: '请输入', trigger: 'blur'}],//名称
                    IPAddress:[{required: true, message: '请输入:例如：127.0.0.1', trigger: 'blur'}],//ip地址
                    port: [{required: true, message: '请输入', trigger: 'blur'}],//端口
                    moreTime:[{required: true, message: '请输入', trigger: 'blur'}],//超时时间
                    reciveTime:[{required: true, message: '请输入', trigger: 'blur'}],//接收时间
                    seriaPort:[{required: true, message: '请输入', trigger: 'blur'}],// 串口号
                    baudRate:[{required: true, message: '请输入', trigger: 'blur'}],//波特率
                    Imei:[{required: true, message: '请输入', trigger: 'blur'}],//Imei号
                    endName:[{required: true, message: '请输入', trigger: 'blur'}],//远程端口
                    concentratorAgreement:[{required: true, message: '请输入', trigger: 'blur'}]//网关协议
                },
                setTimer:null,
                // isConfigMid:false,
                // configMidDataList: [],
                // configMidData: '',
            }
        },
        created() {
            this.getData();
            this.getCommunication();//获取通讯协议
            this.getGateway();//获取网关协议
            // this.getMidData();//获取中继器列表

            var $_this = this;
            this.setTimer = setInterval(function () {
                apiLoading.isShow = false;
                $_this.getData();
            },5000)

        },
        beforeDestroy(){
            clearInterval(this.setTimer);
            this.setTimer = null;
        },
        watch:{
            $route(to,from){
                if(this.$route.path == '/GatewayAdministration'){
                    var $_this = this;
                    this.setTimer = setInterval(function () {
                        $_this.getData();
                    },5000)
                }else{
                    clearInterval(this.setTimer);
                    this.setTimer = null;
                }
            },
            multipleSelection:function (val) {
                if(val.length>0){
                    clearInterval(this.setTimer);
                    this.setTimer = null;
                }else{
                    var $_this = this;
                    this.setTimer = setInterval(function () {
                        $_this.getData();
                    },5000)
                }
            }
        },

        methods: {
            //页面通讯配置显示转换
            formatAdd(row, column, cellValue){
                var str = "";
                // console.log(row)
                if(!row.comType){
                    return str;
                }
                if(row.comType == 60002){
                    str = (row.port ? row.port:'') + ':' + (row.baudRate ? row.baudRate:'')
                }else{
                    str = (row.ipAddress ? row.ipAddress:'') + ':' + (row.port?row.port:'')
                }
                return str;

            },
            // 分页导航
            handleCurrentChange(val) {
                this.cur_page = val;
                console.log(this.cur_page)
                this.getData();
            },

            //获取数据以及分页
            getData(){
                //分页接口
                getAdministrationPage({
                    pageNum:this.cur_page,
                    pageSize:this.page_size
                }).then((res) =>{
                     console.log(res)
                    // console.log(res.data)
                    this.tableData = res.data.list;
                    this.page_total = res.data.total;
                    this.page_size =res.data.pageSize;
                    // console.log(this.page_size)
                })
            },
            //获取通讯协议
            getCommunication(){
                getCategory({
                    "dicName":"通讯协议"
                }).then((res) =>{
                    console.log(res)
                    this.communicationType =res.expandData;
                    console.log(this.communicationType)
                })
            },
            //获取网关协议
            getGateway(){
                getCategory({
                    "dicName":"网关协议"
                }).then((res) =>{
                    // console.log(res)
                    this.concentratorAgreementType =res.expandData;
                    console.log(this.concentratorAgreementType)
                })
            },
            //获取数据以及分页
            // getMidData(){
            //
            //     getRepeaterLinkList({
            //
            //     }).then((res) =>{
            //         console.log(res)
            //         this.configMidDataList = res.datas;
            //     })
            // },
            //勾选选中当前行
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            //点击行触发，选中或不选中复选框
            handleRowClick(row, column, event){
                this.$refs.multipleTable.toggleRowSelection(row);
            },
            //点击当前行选中当前行
            handleSelectionChangeTable(val){
                this.multipleSelection = val;
            },
            // configMid(){
            //     if(this.multipleSelection.length < 1){
            //         this.$message.error('请选择需要修改的网关');
            //         return ;
            //     }
            //     if(this.multipleSelection.length > 1){
            //         this.$message.error('一次只能操作一个网关');
            //         return ;
            //     }
            //     clearInterval(this.setTimer);
            //     this.setTimer = null;
            //
            //     this.isConfigMid = true;
            // },
            // savaConfig(){
            //     console.log(this.multipleSelection[0]);
            //     console.log(this.configMidData);
            //     setDataCollectorRepeaterInfo({
            //         cId:this.multipleSelection[0].deviceId,
            //         rId:this.configMidData
            //     }).then((res)=>{
            //         if(res.success){
            //             this.isConfigMid = false;
            //             this.$message.success(res.message);
            //             this.getData();
            //         }else{
            //             this.$message.error(res.message);
            //         }
            //     })
            //
            //
            // },
            // 保存编辑
            save() {
                if (this.formValidate(this.form)) {
                    if(this.isEditInfo) {
                        // TCP/IP通讯修改
                        if (this.form.communication == this.communicationType[0].value) {
                            var postData = {
                                "deviceId":this.multipleSelection[0].deviceId,
                                'comType': this.form.communication,//通讯协议
                                'deviceCode': this.form.code, //编号
                                'deviceNo': this.form.order,  //产品序号
                                'deviceName': this.form.name,  //设备名称
                                'ipAddress': this.form.IPAddress,  //ip地址
                                'port': this.form.port, //端口
                                'sendOutTime': this.form.moreTime,// 发送超时
                                'receiveOutTime': this.form.reciveTime,// 接收超时
                                "comProtocal": this.form.concentratorAgreement,//网关协议
                                "deviceStatus": '未连接'
                            }
                            updateDataCollector(postData).then((res) => {
                                if (res.success) {
                                    console.log(res.seccess)
                                    this.$message.success(`修改成功`);
                                    this.addVisible = false;
                                    this.getData();
                                } else {
                                    this.$message.error(res.message);
                                }
                            })
                            return;

                        }else if(this.form.communication ==this.communicationType[1].value) {
                            var postData = {
                                "deviceId":this.multipleSelection[0].deviceId,
                                'comType': this.form.communication,//通讯协议
                                'deviceCode': this.form.code, //编号
                                'deviceNo': this.form.order,  //产品序号
                                'deviceName': this.form.name,  //设备名称
                                'baudRate': this.form.baudRate, //波特率
                                'dataBits': this.form.numPosition,  //数据位
                                'port': this.form.seriaPort,//串口号
                                'parity': this.form.parityBit, //奇偶校验
                                'stopBits': this.form.stopPosition,  //停止位
                                'sendOutTime': this.form.moreTime,// 发送超时
                                'receiveOutTime': this.form.reciveTime,// 接收超时
                                "comProtocal": this.form.concentratorAgreement,//网关协议
                                "deviceStatus": '未连接',
                            }
                            updateDataCollector(postData).then((res) => {
                                if (res.success) {
                                    this.$message.success(`修改成功`);
                                    this.addVisible = false;
                                    this.getData();
                                } else {
                                    this.$message.error(res.message);
                                }
                            })
                            return;
                        }else if(this.form.communication ==this.communicationType[2].value) {
                            var postData = {
                                "deviceId":this.multipleSelection[0].deviceId,
                                'comType': this.form.communication,//通讯协议
                                'deviceCode': this.form.code, //编号
                                'deviceNo': this.form.order,  //产品序号
                                'deviceName': this.form.name,  //设备名称
                                'ipAddress': this.form.IPAddress,  //ip地址
                                'port': this.form.port, //端口
                                'sendOutTime': this.form.moreTime,// 发送超时
                                'receiveOutTime': this.form.reciveTime,// 接收超时
                                'clientName': this.form.endName,  //远程名称
                                'imei': this.form.Imei, //imei设备编号
                                "comProtocal": this.form.concentratorAgreement,//网关协议
                                "deviceStatus": '未连接'
                            }
                            updateDataCollector(postData).then((res) => {
                                if (res.success) {
                                    this.$message.success(`修改成功`);
                                    this.addVisible = false;
                                    this.getData();
                                } else {
                                    this.$message.error(res.message);
                                }
                            })
                            return ;
                        }

                    }
                   //新增TCP通讯方式
                    if(this.form.communication ==this.communicationType[0].value){
                        var postData={
                            'comType':this.form.communication,//通讯协议
                            'deviceCode':this.form.code, //编号
                            'deviceNo':this.form.order,  //产品序号
                            'deviceName':this.form.name,  //设备名称
                            'ipAddress':this.form.IPAddress,  //ip地址
                            'port':this.form.port, //端口
                            'sendOutTime':this.form.moreTime,// 发送超时
                            'receiveOutTime':this.form.reciveTime,// 接收超时
                            "comProtocal":this.form.concentratorAgreement,//网关协议
                            "deviceStatus":'未连接'
                        }
                        addDataCollector(postData).then((res) => {
                            console.log(postData)
                            if (res.success) {
                                console.log(res.seccess)
                                this.$message.success(`添加成功`);
                                this.addVisible = false;
                                this.getData();
                            } else {
                                this.$message.error(res.message);
                            }
                        })
                        //新增COM通讯方式
                    }else if(this.form.communication ==this.communicationType[1].value){
                           var postData={
                               'comType':this.form.communication,//通讯协议
                               'deviceCode':this.form.code, //编号
                               'deviceNo':this.form.order,  //产品序号
                               'deviceName':this.form.name,  //设备名称
                               'baudRate':this.form.baudRate, //波特率
                               'dataBits':this.form.numPosition,  //数据位
                               'port':this.form.seriaPort,//串口号
                               'parity':this.form.parityBit, //奇偶校验
                               'stopBits':this.form.stopPosition,  //停止位
                               'sendOutTime':this.form.moreTime,// 发送超时
                               'receiveOutTime':this.form.reciveTime,// 接收超时
                               "comProtocal":this.form.concentratorAgreement,//网关协议
                               "deviceStatus":'未连接',
                           }

                        addDataCollector(postData).then((res) => {
                            // alert(111)
                            if (res.success) {
                                console.log(postData)
                                this.$message.success(`添加成功`);
                                this.addVisible = false;
                                this.getData();
                            } else {
                                this.$message.error(res.message);
                            }
                        })
                        //新增Vircom通讯方式
                    }else if(this.form.communication ==this.communicationType[2].value){
                        var postData={
                            'comType':this.form.communication,//通讯协议
                            'deviceCode':this.form.code, //编号
                            'deviceNo':this.form.order,  //产品序号
                            'deviceName':this.form.name,  //设备名称
                            'ipAddress':this.form.IPAddress,  //ip地址
                            'port':this.form.port, //端口
                            'sendOutTime':this.form.moreTime,// 发送超时
                            'receiveOutTime':this.form.reciveTime,// 接收超时
                            'clientName':this.form.endName,  //远程名称
                            'imei':this.form.Imei, //imei设备编号
                            "comProtocal":this.form.concentratorAgreement,//网关协议
                            "deviceStatus":'未连接'
                        }
                        addDataCollector(postData).then((res) => {
                            if (res.success) {
                                this.$message.success(`添加成功`);
                                this.addVisible = false;
                                this.getData();
                            } else {
                                this.$message.error(res.message);
                            }
                        })
                    }
                }
            },
            // 确定删除
            deleteRow(){
                var delCountId = new Array();
                for(var i=0;i<this.multipleSelection.length;i++){
                    // console.log(this.multipleSelection[i].deviceId)
                    delCountId.push(this.multipleSelection[i].deviceId)
                }
                // console.log(delCountId);
                batchDeleteDataCollectors({
                    ids:delCountId
                }).then((res)=>{
                    console.log(res)
                    if(res.success){
                        this.$message.success('删除成功');
                        this.delVisible = false;
                        this.getData();
                    }else{
                        this.$message.error(res.message)
                    }
                })

            },
            //点击新增
            addCount(){
                this.addVisible = true;
                this.isEditInfo = false;
                this.diologTitle = '新增网关';
                this.form= {
                         name: '',//名称
                        order: '',//序号
                        code:'',//编号
                        communication:this.communicationType[0].value,//通讯方式
                        IPAddress:'',//IP地址
                        port:'',//端口
                        moreTime:'60000',//超时时间
                        reciveTime:'60000',//接收时间
                        seriaPort:'',// 串口号
                        baudRate:'',//波特率
                        numPosition:'',//数据位
                        stopPosition:'',//停止位
                        parityBit:'',//奇偶校验位
                        Imei:'',//Imei号
                        endName:'',//远程端口
                    concentratorAgreement:this.concentratorAgreementType[0].value//网关协议
                }
            },
            formatTime(row, column, cellValue, index){
                return famatDatesTimes(cellValue);
            },

            //点击修改
            editRole(){
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要修改的网关');
                }else
                if(this.multipleSelection.length == 1){
                    console.log(this.multipleSelection)
                    this.addVisible = true;
                    this.isEditInfo = true;
                    this.diologTitle = '修改网关';
                    this.form.name= this.multipleSelection[0].deviceName,//名称
                        this.form.order= this.multipleSelection[0].deviceNo,//序号
                        this.form.code=this.multipleSelection[0].deviceCode,//编号
                        this.form.concentratorAgreement =this.multipleSelection[0].comProtocal//网关协议
                        this.form.communication=this.multipleSelection[0].comType,//通讯方式
                        this.form.IPAddress=this.multipleSelection[0].ipAddress,//IP地址
                        this.form.port=this.multipleSelection[0].port,//端口
                        this.form.moreTime=this.multipleSelection[0].receiveOutTime,//超时时间
                        this.form.reciveTime=this.multipleSelection[0].sendOutTime,//接收时间
                        this.form.seriaPort=this.multipleSelection[0].port// 串口号
                        this.form.baudRate=this.multipleSelection[0].baudRate,//波特率
                        this.form.numPosition=this.multipleSelection[0].dataBits,//数据位
                        this.form.stopPosition=this.multipleSelection[0].stopBits,//停止位
                       this.form.parityBit=this.multipleSelection[0].parity,//奇偶校验位
                        this.form.Imei=this.multipleSelection[0].imei,// imei号
                    this.form.endName=this.multipleSelection[0].clientName//远程端口名称
                }else{
                    this.$message.error('一次只能修改一个网关');
                }
                console.log(this.multipleSelection)
            },
            //点击删除
            delCount(){
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要删除的网关');
                }else
                {
                    this.delVisible = true;
                }
            },
            connect(v){

                // return;
                if(this.multipleSelection.length < 1){
                    this.$message.error('请选择需要操作的网关');
                    return ;
                }
                if(this.multipleSelection.length >1){
                    this.$message.error('每次只能操作一个网关');
                    return;
                }

                var str = 'conn,'+this.multipleSelection[0].deviceId+','+this.multipleSelection[0].comTypeName+','
                    +this.multipleSelection[0].port.substring(this.multipleSelection[0].port.indexOf('m')+1)
                +','+ v;


                this.socketApi.sendSock(this,str,(data)=>{
                    this.getData();
                    this.$message.error(JSON.parse(data).message)
                });

                console.log(str)
                // if(v==1){
                //     console.log('链接网关')
                // }else{
                //     console.log('断开网络')
                // }
            },

            //验证
            formValidate(formname) {
                if (formname.communication ==this.communicationType[0].value){
                    if ( formname.code && formname.name  && formname.IPAddress && formname.port && formname.moreTime &&formname.reciveTime){
                        if (!regNumber(formname.code)) {
                                                this.$message.error('编号只能为数字');
                                                return false;
                        }
                        if (!regNumber(formname.port)) {
                            this.$message.error('端口号只能为数字');
                            return false;
                        }
                        if (!regIpAddress(formname.IPAddress)) {
                            this.$message.error('请输入正确的IP地址');
                            return false;
                        }
                        if (!regNumber(formname.moreTime)) {
                                            this.$message.error('发送超时时间只能为数字');
                                            return false;
                        }
                        if (!regNumber(formname.reciveTime)) {
                                            this.$message.error('接收超时时间只能为数字');
                                            return false;
                        }
                        return true;
                    }else{
                        if (!formname.code) {
                                            this.$message.error('请输入编号');
                                            return false;
                        }
                        if (!formname.name) {
                                            this.$message.error('请输入名称');
                                            return false;
                        }
                        if (!formname.IPAddress) {
                                        this.$message.error('请输入IP地址');
                                        return false;
                        }
                        if (!formname.port) {
                                        this.$message.error('请输入端口号');
                                        return false;
                        }
                        if (!regNumber(formname.moreTime)) {
                                            this.$message.error('请输入发送超时时间');
                                            return false;
                        }
                        if (!regNumber(formname.reciveTime)) {
                                            this.$message.error('请输入接收超时时间');
                                            return false;
                        }
                    }
                }
                if(formname.communication ==this.communicationType[1].value){
                    if (formname.code && formname.name && formname.seriaPort  && formname.baudRate && formname.moreTime &&formname.reciveTime){
                        if (!regNumber(formname.code)) {
                            this.$message.error('编号只能为数字');
                            return false;
                        }
                        if (!regNumber(formname.moreTime)) {
                            this.$message.error('发送超时时间只能为数字');
                            return false;
                        }
                        if (!regNumber(formname.reciveTime)) {
                            this.$message.error('接收超时时间只能为数字');
                            return false;
                        }
                        return true;
                    }else{
                        if (!formname.code) {
                            this.$message.error('请输入编号');
                            return false;
                        }
                        if (!formname.name) {
                            this.$message.error('请输入名称');
                            return false;
                        }
                        if (!formname.seriaPort){
                            this.$message.error('请选择串口号');
                            return false;
                        }
                        if (!formname.baudRate){
                            this.$message.error('请选择波特率');
                            return false;
                        }
                        if (!regNumber(formname.moreTime)) {
                            this.$message.error('请输入发送超时时间');
                            return false;
                        }
                        if (!regNumber(formname.reciveTime)) {
                            this.$message.error('请输入接收超时时间');
                            return false;
                        }
                    }
                }
                if(formname.communication ==this.communicationType[2].value){
                    if (formname.code && formname.name && formname.IPAddress && formname.port && formname.moreTime
                        && formname.reciveTime && formname.Imei && formname.endName){
                        if (!regNumber(formname.code)) {
                            this.$message.error('编号只能为数字');
                            return false;
                        }
                        if (!regNumber(formname.port)) {
                            this.$message.error('端口号只能为数字');
                            return false;
                        }
                        if (!regIpAddress(formname.IPAddress)) {
                            this.$message.error('请输入正确的IP地址');
                            return false;
                        }
                        if (!regNumber(formname.moreTime)) {
                            this.$message.error('发送超时时间只能为数字');
                            return false;
                        }
                        if (!regNumber(formname.reciveTime)) {
                            this.$message.error('接收超时时间只能为数字');
                            return false;
                        }
                        return true;
                    }else{
                        if (!formname.code) {
                                            this.$message.error('请输入编号');
                                            return false;
                        }
                        if (!formname.name) {
                                            this.$message.error('请输入名称');
                                            return false;
                        }
                        if (!formname.IPAddress) {
                                            this.$message.error('请输入IP地址');
                                            return false;
                        }
                        if (!formname.port) {
                                            this.$message.error('请输入端口号');
                                            return false;
                        }
                        if (!formname.port) {
                                            this.$message.error('请输入发送超时时间');
                                            return false;
                        }
                        if (!formname.reciveTime) {
                                            this.$message.error('请输入接收超时时间');
                                            return false;
                        }
                        if (!formname.Imei) {
                            this.$message.error('请输入Imei号');
                            return false;
                        }
                        if (!formname.endName) {
                            this.$message.error('请输入远程端口名称');
                            return false;
                        }
                    }
                }
            }
        }
    }
</script>

<style scoped>

    /deep/ .el-form-item__content{
    margin-left: 0 !important;
}

    .handle-box {
        margin-bottom: 20px;
        margin-top: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .mr10{
        margin-right: 10px;
    }
    .el-dialog{
        max-height:600px;
        overflow-y: scroll;
    }

    .el-select{
        width:50%;
    }
    .el-input{
        width:50%;
    }
    /*.limit-small .el-form-item{*/
    /*    float: left;*/
    /*    width: 50%;*/
    /*}*/
    .limit-small{
        overflow: hidden;
    }
    /*.limit-width{*/
    /*    width: 50%;*/
    /*    float: left;*/
    /*}*/
    .active{
            width: 50%;
            float: left;
    }
    /*.el-input{*/
    /*    width: 80%;*/
    /*}*/
    .el-scrollbar .el-scrollbar__view .el-select-dropdown__item{
        height: auto;
        max-height: 274px;
        padding: 0;
        overflow: hidden;
        overflow-y: auto;
    }
    .el-form-item::after, .el-form-item::before {
        clear: both;
    }
</style>
